package com.spring.sunflower.userinfo

import android.content.Intent
import android.graphics.Color
import android.view.View
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.spring.sunflower.R
import com.spring.sunflower.base.BaseActivity
import com.spring.sunflower.bean.CheckApplyFaceVerifyBean
import com.spring.sunflower.bean.FaceAuthStatusBean
import com.spring.sunflower.common.CommonContract

/**
 * Created by Kevin on 2021/8/15<br/>
 *
 * Describe:<br/>
 */
class AuthCenterActivity : BaseActivity<AuthCenterPresenter>(), CommonContract.AuthCenterView,
    View.OnClickListener {
    private var tvRealAuthStatus: TextView? = null
    private var tvBeautyAuthStatus: TextView? = null
    private var clRealAuth: ConstraintLayout? = null
    private var clBeautyAuth: ConstraintLayout? = null
    private var isRealAuthClickable = false
    private var isBeautyAuthClickable = false
    override fun initView() {
        tvTitle.text = "认证中心"
        tvRealAuthStatus = findViewById(R.id.tvAuthStatus)
        tvBeautyAuthStatus = findViewById(R.id.tvAuthStatusBeauty)
        clRealAuth = findViewById(R.id.clRealAuth)
        clBeautyAuth = findViewById(R.id.clBeautyAuth)
        clBeautyAuth!!.setOnClickListener(this)
        clRealAuth!!.setOnClickListener(this)
    }

    override fun onResume() {
        super.onResume()
        mPresenter.getFaceAuthStatus()
        mPresenter.getCheckFaceAuthStatus()
    }

    override fun getLayoutID(): Int = R.layout.activity_auth_center

    override fun setPresenter(): AuthCenterPresenter = AuthCenterPresenter(this)
    override fun showFaceAuthStatus(data: FaceAuthStatusBean.DatasBean?) {
        when (data!!.status) {
            "0" -> {
                isBeautyAuthClickable = false
                tvBeautyAuthStatus?.let {
                    it.text = "审核中"
                    it.setTextColor(Color.parseColor("#FBA501"))
                }
            }
            "1" -> {
                isBeautyAuthClickable = false
                tvBeautyAuthStatus?.let {
                    it.text = "已认证"
                    it.setTextColor(Color.parseColor("#54B83C"))
                }
            }
            "2" -> {
                isBeautyAuthClickable = false
                tvBeautyAuthStatus?.let {
                    it.text = "已拒绝"
                    it.setTextColor(Color.parseColor("#FF7373"))
                }
            }
            "3" -> {
                isBeautyAuthClickable = true
                tvBeautyAuthStatus?.let {
                    it.text = "未认证"
                    it.setTextColor(getColorX(R.color.red_1))
                }
            }
        }

    }


    override fun showCheckFaceAuthStatus(data: CheckApplyFaceVerifyBean.DatasBean?) {
        val authenticate = data!!.authenticate
        if (authenticate) {
            isRealAuthClickable = false
            tvRealAuthStatus?.let {
                it.text = "已认证"
                it.setTextColor(Color.parseColor("#54B83C"))
            }
        } else {
            isRealAuthClickable = true
            tvRealAuthStatus?.let {
                it.text = "未认证"
                it.setTextColor(getColorX(R.color.red_1))
            }
        }

    }

    override fun beautyAuthApplySuccess() {
    }

    override fun onClick(v: View?) {
        if (isFastClick) return
        when (v!!.id) {
            R.id.clBeautyAuth -> {
                if (isBeautyAuthClickable) {
                    startNewActivity(AuthBeautyActivity::class.java)
                }
            }
            R.id.clRealAuth -> {
                if (isRealAuthClickable) {
                    startActivity(Intent(this@AuthCenterActivity, AuthRealActivity::class.java))
                }
            }
        }
    }
}